package rxjava.operators;

import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.functions.BiFunction;
import io.reactivex.functions.Consumer;

/**
 * User: Administrator
 * Date: 2021/3/24
 * Time: 13:47
 * Description:
 */
public class ZipDemo {
    public static void main(String[] args) {
        Observable.zip(getStringObservable(), getIntegerObservable(), new BiFunction<String, Integer, Object>() {
            @Override
            public Object apply(String s, Integer integer) throws Exception {
                return s + integer;
            }
        }).subscribe(o -> System.out.println(o));
    }

    public static Observable<String> getStringObservable() {
        return Observable.create(observableEmitter -> {
            observableEmitter.onNext("A");
            observableEmitter.onNext("B");
            observableEmitter.onNext("C");
            observableEmitter.onNext("D");
        });
    }

    public static Observable<Integer> getIntegerObservable() {
        return Observable.create(observableEmitter -> {
           observableEmitter.onNext(1);
           observableEmitter.onNext(2);
           observableEmitter.onNext(3);
           observableEmitter.onNext(4);
           observableEmitter.onNext(5);
        });
    }
}
